package com.dun.mvc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dun.mvc.service.UserServiceImpl;
import com.dun.mvc.vo.User;

@Controller
public class UserController {

	@Autowired
	private UserServiceImpl userService;

	@ModelAttribute
	public User newRequest() {
		return new User();
	}

	@RequestMapping(value = "/user/createUser", method = RequestMethod.POST)
	public String createUserSuccess(User user, Model model) {
		model.addAttribute("success", "Success......");
		//Values From previous Page
		model.addAttribute(user);
		List<User> users = userService.getUsers();
		//Values From DB
		model.addAttribute("usersList", users);
		return "success";
	}
	
	@RequestMapping(value = "/user/createUserLoad", method = RequestMethod.GET)
	public String createUserLoad() {
		return "createUser";
	}

	@RequestMapping(value = "/user/home", method = RequestMethod.GET)
	public String home() {
		return "welcome";
	}
	
	@RequestMapping(value = "/user/getUser", method = RequestMethod.GET)
	public String getUser(Model model) {
		List<User> users = userService.getUsers();
		model.addAttribute("usersList", users);
		return "userDetails";
	}
	@RequestMapping(value = "/user/getUserDetails.htm", method = RequestMethod.POST)
	public String getUserDetails(User user, Model model) {
		System.out.println(user.getUserId());
		return "TODO";
	}
	

}